package com.example.deliveryapplication.sql

import androidx.room.*
import com.example.deliveryapplication.entity.*

@Dao
interface PlanItemDao {
    @Insert
    fun insertChart(bearingModel: PlanItem): Long
    @Query("select * from `PlanItem` where planId=:planId")
    fun loadAllChart(planId:String): List<PlanItem>
    @SuppressWarnings(RoomWarnings.CURSOR_MISMATCH)
    @Transaction
    @Query("SELECT * FROM PlanItem INNER JOIN Client ON PlanItem.clientId = Client.id INNER JOIN BearingModel ON PlanItem.modelId = BearingModel.id  where planId=:planId")
    fun getPlanItemsWithClients(planId:String): List<PlanItemWithClient>
    @Insert
    fun insertPlanItems(bearingModels: List<PlanItem>): List<Long>
    @SuppressWarnings(RoomWarnings.CURSOR_MISMATCH)
    @Query("select * from `PlanItem` Left JOIN BearingModel ON `PlanItem`.modelId =BearingModel.id where `BearingModel`.id=:modelId")
    fun loadPlanItemByModelId(modelId:String): List<PlanItem>
    @SuppressWarnings(RoomWarnings.CURSOR_MISMATCH)
    @Query("select * from `PlanItem` Left JOIN Client ON `PlanItem`.clientId =Client.id where `Client`.id=:clientId")
    fun loadPlanItemByClientId(clientId:String): List<PlanItem>
    @Delete
    fun deleteByPlanId(list:List<PlanItem>):Int
    @Query("select * from `PlanItem` where planItemId=:Id")
    fun loadPlanItem(Id:String): PlanItem
}